/* -----------------------------------------------------------------------------
 * PROJECT    : lwf_handlers
 * FILE       : PdfHandler.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Jan 3, 2011  mycodetalks			       Created
 */
package net.lwf.pdf.util;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.List;

import net.lwf.file.util.FileHandler;


import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

/**
 * Class description goes here
 */
public abstract class PdfHandler {
	

    
    private static final int DEFAULT_ROWS = 1;
    private static final int DEFAULT_COLUMNS = 1;
	
    //Moved most of the methods to the handler classes
    
//	public abstract void getContent(Document document) throws DocumentException;
//	
//	public abstract Element processCellData(Object object);
//
//	public abstract int getRows();
//
//	public abstract int getColumns();
//	
//	public abstract List<?> getTabularData();

//	public void generate(Document document) {
//		document.open();
//		try {
//			List<?> tabulardata = getTabularData();
//			if(tabulardata != null) {
//				this.processTabularData(document, tabulardata);
//			}
//			else {
//				getContent(document);
//			}
//			
//		} catch (DocumentException e) {
//			e.printStackTrace();
//		}
//		document.close();
//	}
	
/*	//To the Base Action Class
	public Document getPortraitDocument() {
		return new Document(PageSize.A4, 50, 50, 50, 50);
	}
	//To the Base Action Class
	public Document getLandScapeDocument() {
		return new Document(PageSize.A4.rotate(), 50, 50, 50, 50);
	}*/
	
//	private void processTabularData(Document document, List<?> tabulardata) throws DocumentException {
//		document.add(new Phrase(" "));
//		int columns = getColumns() == 0 ? getColumns() : DEFAULT_COLUMNS;
//		int rows = getRows() == 0 ? getRows() : DEFAULT_ROWS;
//		int datasize = tabulardata.size();
//		
//		PdfPTable table = new PdfPTable(columns);
//		table.setSpacingBefore(20);
//		int dataindex = 0;
//		for(int i=0; i<rows; i++) {
//			for(int j=0; j<columns; j++) {
//				System.out.println("============> i = " + i + "; j = " + j + "; Data size: " + dataindex);
//				if(dataindex+1 <= datasize) {
//					Object obj = (Object) tabulardata.get(dataindex);
//					PdfPTable tablecell = (PdfPTable) processCellData(obj);
//					table.addCell(tablecell);
//				}
//				else {
//					table.addCell(new Phrase(" "));
//					System.out.println("empty cell");
//				}
//				dataindex++;
//			}
//			table.completeRow();
//			
//		}
//		
//		document.add(table);
//	}
	
/*	private Document getDocument(Rectangle paperorientation, String directory, String filename) {
		String fullfilepath = directory + "/" + filename;
		FileHandler.createFile(directory, fullfilepath);
		//   For portrait                              L   R   T   B
		Document document = new Document(paperorientation, 50, 50, 75, 50);
		
		try {
			PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fullfilepath));
			//----------------Add header and footer
			LwfHeaderFooter event = new LwfHeaderFooter();
	         writer.setPageEvent(event);
	        //----------------Add encryption to the document
	         //writer.setEncryption(null, OWNER, PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);
	         //Another way
	         writer.setEncryption(null, OWNER, PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);
	         writer.createXmpMetadata();
		} catch (FileNotFoundException e) {

			e.printStackTrace();
		} catch (DocumentException e) {

			e.printStackTrace();
		}
		
		return document;
	}*/

} // PdfHandler



